<?php session_start(); ?>
<?php include_once('misc/class_config.php'); ?>

<?php 
	include('access_control/page_access.php');
	setPreviousPage();
	
	$currentUser = new user();
	$currentUser->isLoggedIn();
	$currentUser->isTimedOut();
	
	$existingProduct = new product();
	$productMessage = '';
?>

<?php
	if(isset($_REQUEST['action']))
	{	
		if(isset($_REQUEST['code']))
		{
			$existingProduct->code = $_REQUEST['code'];
			
			if($_REQUEST['action']=='edit')
			{
				if($currentUser->loggedIn && $currentUser->type="admin")
				{
				}
				header("location:".getPreviousPage());
				exit();
			}
			else if($_REQUEST['action']=='delete')
			{
				if($currentUser->loggedIn && $currentUser->type="admin")
				{
					if($existingProduct->deleteProduct())
					{
						
					}
					else
					{	
						
					}
				}
				header("location:".getPreviousPage());
				exit();
			}
		}
	}
?>
<?php
	if(!$currentUser->loggedIn)
	{
		include_once "controller/loginformcontroller.php"; 
	}
?>

<?php $pageTitle = "Products | Everything"; ?>
<?php include('layout/page_start.php'); ?>
<?php include('layout/page_header.php'); ?>

<?php
	if(!$currentUser->loggedIn)
	{
		include('layout/loginform.php'); 
	}
?>

<?php include('layout/menu_bar.php'); ?>

<div id="main_content_div">
	
	<?php
		if($currentUser->loggedIn)
		{
			if($currentUser->timedOut)
			{
				include_once "layout/timeout.php";
				$currentUser->timeoutUser();
			}
		}
		echo '<div class="page_action_msg_div"><a>'.$productMessage.'</a></div>';
		include_once "layout/product_page.php";
	?>
	
	</br>
</div>
<?php include('layout/page_footer.php'); ?>
<?php include('layout/page_end.php'); ?>
<?php setCurrentPage();?>
